package com.situ.layuimini.handler;

import com.situ.layuimini.exception.NoLoginException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import java.util.HashMap;
import java.util.Map;

@ControllerAdvice
public class MyExceptionHandler {

    @ExceptionHandler(value = NoLoginException.class)
    public ResponseEntity<Object> handler1() {
        return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(null);
    }

    @ExceptionHandler(value = Exception.class)
    public ResponseEntity<Object> handler2() {
        Map<String, String> vo = new HashMap<>();
        vo.put("code", "1");
        vo.put("msg", "内部处理错误，请稍候再试。");
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(vo);
    }
}
